package 策略模式.v2;

/**
 * 枚举类
 * <p>
 * 调整一下枚举类，增加一个GeneralChannelRule属性，并且给对应渠道构建对应的GeneralChannelRule实现类，新增一个match() 匹配方法
 */
public enum ChannelRuleEnum {

    /**
     * 头条
     */
    TOUTIAO("TOUTIAO", new TouTiaoChannelRule()),
    /**
     * 腾讯
     */
    TENCENT("TENCENT", new TencentChannelRule()),
    ;

    public String name;

    public GeneralChannelRule channel;

    ChannelRuleEnum(String name, GeneralChannelRule channel) {
        this.name = name;
        this.channel = channel;
    }

    /**
     * match() 匹配方法
     *
     * @param name
     */
    public static ChannelRuleEnum match(String name) {
        ChannelRuleEnum[] values = ChannelRuleEnum.values();
        for (ChannelRuleEnum value : values) {
            if (value.name.equals(name)) {
                return value;
            }
        }
        return null;
    }

    public String getName() {
        return name;
    }

    public GeneralChannelRule getChannel() {
        return channel;
    }

}
